package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.service.OrderService;
import com.sky.service.SetmealService;
import com.sky.vo.BusinessDataVO;
import com.sky.vo.DishOverViewVO;
import com.sky.vo.OrderOverViewVO;
import com.sky.vo.SetmealOverViewVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

/**
 * 工作台
 */
@RestController
@RequestMapping("/admin/workspace")
@Slf4j
@Api(tags = "工作台相关接口")
public class WorkSpaceController {
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private DishService dishService;
    @Autowired
    private OrderService orderService;
    @GetMapping("overviewSetmeals")
    @ApiOperation("套餐总览")
    public Result<SetmealOverViewVO> overviewSetmeals(){
        log.info("套餐总览:");
        SetmealOverViewVO setmealOverViewVO= setmealService.getCountByStatus();
        return Result.success(setmealOverViewVO);
    }

    @GetMapping("overviewDishes")
    @ApiOperation("菜品总览")
    public Result<DishOverViewVO> overviewDishes(){
        log.info("菜品总览:");
        DishOverViewVO dishOverViewVO= dishService.getCountByStatus();
        return Result.success(dishOverViewVO);
    }

    @GetMapping("overviewOrders")
    @ApiOperation("订单管理")
    public Result<OrderOverViewVO> overviewOrders(){
        log.info("订单管理:");
        OrderOverViewVO orderOverViewVO= orderService.getOverviewOrders();
        return Result.success(orderOverViewVO);
    }

    @GetMapping("businessData")
    @ApiOperation("查看今日数据")
    public Result<BusinessDataVO> businessData(){
        // 获取当前日期
        LocalDate now = LocalDate.now();
        // 设置时间范围的开始时间为当前日期的00:00
        LocalDateTime begin = LocalDateTime.of(now, LocalTime.MIN);
        // 设置时间范围的结束时间为当前日期的23:59:59.999999999
        LocalDateTime end = LocalDateTime.of(now, LocalTime.MAX);
         log.info("时间范围：{}到{}", begin, end);
        BusinessDataVO businessDataVO= orderService.getBusinessData(begin,end);
        return Result.success(businessDataVO);
    }

}
